package leetcode.每日一题;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2021/6/18 10:15
 * @description：
 */
public class 跳跃游戏 {

    @Test
    public void Test() {
        Solution solution = new Solution();
        System.out.println(solution.canJump(new int[]{4,2,0,0,1,1,4,4,4,0,4,0}));

    }

    class Solution {
        public boolean canJump(int[] nums) {
            int n = nums.length;
            if (n == 0) return true;
            int mostRight = nums[0];
            for (int i = 0; i < n; i++) {
                if (i <= mostRight) {
                    mostRight = Math.max(mostRight, nums[i] + i);
                }
                if (mostRight >= n - 1) return true;
            }
            return false;
        }
    }
}
